﻿-- DROP FUNCTION valida_num_adherente(character varying);

CREATE OR REPLACE FUNCTION valida_num_adherente(
    IN xnum_adherente character varying,
    OUT num_adout character varying,
	OUT flag boolean,
    OUT numerror character varying,
    OUT msjerror character varying )
RETURNS record AS
$body$
declare xsnum_adherente varchar(100);
begin
    numerror := 0;
    msjerror := '';
    
   	SELECT 
	
	num_adherente
	into 
	xsnum_adherente
	
	FROM empresa
          
	where (num_adherente) = xnum_adherente;
  
		IF FOUND THEN
			num_adout:=xsnum_adherente;
			flag=TRUE;
			
		ELSE
			flag=FALSE;
			numerror := '1';
			msjerror := 'no encontrado.';
		end if;
end;

$body$
language 'plpgsql' 
